<template>
	<view class="main">
		<u-navbar :is-back="true" title="确认订单	" :background="background" :border-bottom="false" title-color="#fff"
			title-size="35rpx" title-bold="true" back-icon-color="#fff">
		</u-navbar>
		<view class="address">
			<view class="tit">合约地址：</view>
			<view>{{shopdetails.chain_address}} </view>
		</view>
		<view class="shop">
			<view class="left">
				<image :src="shopdetails.img" mode=""></image>
			</view>
			<view class="right">
				<view class="shop_tit">
					{{shopdetails.title}}
				</view>
				<view class="company">
					<image :src="shopdetails.issuer_img" mode=""></image>
					<text>{{shopdetails.issuer_name}}</text>
				</view>
				<view class="money">
					￥{{shopdetails.price}}
				</view>
			</view>
		</view>
		<view class="payment">
			<view class="pay_tit">
				支付方式
			</view>
			<view class="where" v-for="item,index in which" :key="index">
				<view class="give" >
					<image :src="item.image" mode=""></image>
					<text>{{item.title}}</text>
				</view>
			<image  @click="choses(item.id)" class="chose" :src="item.id==where?'../../../static/images/chosed.png':'../../../static/images/chose.png'" mode=""></image>
			<!-- ../../../static/images/chose.png -->
			<!-- <image v-if="!item.flag"  @click="choses(index)"  class="chose" src="../../../static/images/chosed.png" mode=""></image> -->
			</view> 
	
		</view>
		<view class="buy">
			<view class="money">
				<text>￥</text>{{shopdetails.price}}
			</view>
			<view class="button" @click="buy">
				<text>立即购买</text>
			
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#111111',
					// background: 'url(https://cdn.uviewui.com/uview/swiper/1.jpg) no-repeat',
				},
				show: false,
				count:'',
				which:[
					{
					id:1,
					image:'../../../static/images/wx.png',
					title:'微信支付',
					flag:false,
				},
				{
					id:2,
					image:'../../../static/images/zfb.png',
					title:'支付宝支付',
					flag:true,
				},
				{
					id:3,
					image:'../../../static/images/ys.png',
					title:'云闪付支付',
					flag:true,
				},
				],
				where:1,
				shopdetails:{},
				type:''
			}
		},
		onLoad(){
			this.getinfo()
		},
		methods: {
			changehead() {
				this.show = !this.show
			},
			close() {
				this.show = !this.show
			},
			
			getinfo() {
				const that = this
				// #ifdef APP-NVUE
				const eventChannel = that.$scope.eventChannel; // 兼容APP-NVUE
				// #endif
				// #ifndef APP-NVUE
				const eventChannel = that.getOpenerEventChannel();
				// #endif
				eventChannel.on('buy', function(data) {
					console.log(data);
					that.type=data.data.type
					that.shopdetails=data.data.shopdetails
				})
			},
			choses(e){
				console.log(e);
				this.where=e
				// this.which[e].flag=!this.which[e].flag
			},
			//支付
		
			//生成订单
			buy(){
				//藏品
				if(this.type==1){
					global.$http.request({
						url: '/api/order/createOrder',
						data: {
							goods_id: JSON.stringify(this.shopdetails.id),
							token:uni.getStorageSync('token'),
							pay_type:JSON.stringify(this.where)
						}
					}).then(res => {
						if (res.data.code == -2) {
						
							uni.showToast({
								title: '订单生成成功',
								icon: "none",
								mask: true,
								duration: 2000
							})
							global.$http.request({
								url: '/api/order/payOrder',
								data: {
									goods_id: JSON.stringify(this.shopdetails.id),
									token:uni.getStorageSync('token'),
								}
							}).then(money=>{
								if(money.data.code==0){
									console.log(money.data.data);
								}
							})
					setTimeout(function(){
						uni.navigateTo({
							url:'../../indexs/index/index'
						})
					},2000)
						}else if(res.data.code==1){
							
						}
					})
				} else if(this.type==2){
					global.$http.request({
						url: '/api/blind_order/createOrder',
						data: {
							goods_id: JSON.stringify(this.shopdetails.id),
							token:uni.getStorageSync('token'),
							pay_type:JSON.stringify(this.where)
						}
					}).then(res => {
						if (res.data.code == 0) {
							uni.showToast({
								title: '订单生成成功',
								icon: "none",
								mask: true,
								duration: 2000
							})
							global.$http.request({
								url: '/api/order/payOrder',
								data: {
									order_id: JSON.stringify(this.shopdetails.id),
									token:uni.getStorageSync('token'),
								}
							}).then(money=>{
								if(money.data.code==0){
									console.log(money.data.data);
								}
							})
						setTimeout(function(){
							uni.navigateTo({
								url:'../../indexs/index/index'
							})
						},2000)
						}else if(res.data.code==1){
							
						}
					})
				} else if(this.type==3){
					global.$http.request({
						url: '/api/ballot_order/createOrder',
						data: {
							goods_id: JSON.stringify(this.shopdetails.id),
							token:uni.getStorageSync('token'),
							pay_type:JSON.stringify(this.where)
						}
					}).then(res => {
						if (res.data.code == 0) {
							uni.showToast({
								title: '订单生成成功',
								icon: "none",
								mask: true,
								duration: 2000
							})
							global.$http.request({
								url: '/api/order/payOrder',
								data: {
									goods_id: JSON.stringify(this.shopdetails.id),
									token:uni.getStorageSync('token'),
								}
							}).then(money=>{
								if(money.data.code==0){
									console.log(money.data.data);
								}
							})
						setTimeout(function(){
							uni.navigateTo({
								url:'../../indexs/index/index'
							})
						},2000)
						}else if(res.data.code==1){
							
						}
					})
				}
			
			},
		}
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC-Regular, PingFang SC;
		background-color: #111111;
		width: 750rpx;

		.main {
			margin-top: 24rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.address {
				padding: 32rpx 24rpx;
				width: 686rpx;
				background: #181818;
				border-radius: 32rpx;
				opacity: 1;

				.tit {
					font-size: 32rpx;
					font-weight: 400;
					color: #FFFFFF;
					padding-bottom: 20rpx;

				}

				view {
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;


				}
			}

			.shop {
				margin: 24rpx 0;
				width: 686rpx;
				height: 248rpx;
				background: #181818;
				border-radius: 32rpx;
				opacity: 1;
				display: flex;
padding: 24rpx;
				.left {
					width: 200rpx;
					border-radius: 32rpx;
					overflow: hidden;
					
					height: 200rpx;

					image {
						width: 200rpx;
						height: 200rpx;
					}
				}

				.right {
					padding-left: 24rpx;

					.shop_tit {

						font-size: 32rpx;
						font-weight: bold;
						color: #FFFFFF;
					}

					.company {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						opacity: 0.5;
						padding: 16rpx 0 60rpx 0;

						image {
							width: 36rpx;
							height: 36rpx;
						}
					}

					.money {
						font-size: 32rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
					}
				}
			}

			.payment {
				
				width: 686rpx;
				background: #181818;
				border-radius: 32rpx;
				opacity: 1;
			padding: 24rpx;
				.pay_tit {
					padding: 32rpx 0;
					font-size: 32rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
				.where{
					display: flex;
					align-items: center;
					justify-content: space-between;
					// padding: 0 24rpx 32rpx 24rpx;
					padding-bottom: 32rpx;
					.give{
						display: flex;
						align-items: center;
						image{
							width: 48rpx;
							height: 48rpx;
							margin-right: 16rpx;
						}
						font-size: 28rpx;
						font-weight: 400;
						color: #FFFFFF;
					}
					.chose{
						width: 36rpx;
						height: 36rpx;
					}
				}
			}
			.buy {
				position: fixed;
				bottom: 0;
				width: 750rpx;
				background: #151515;
				box-shadow: 0rpx -1rpx 0rpx 2rpx rgba(0, 0, 0, 0.07);
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				opacity: 1;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 32rpx;
			
				.money {
					font-size: 48rpx;
					font-weight: 400;
					color: #FFFFFF;
			
					text {
					padding-right: 4rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: #FFFFFF;
					
					}
			
				}
			
				.button {
					padding: 16rpx 40rpx;
					background: #F3C860;
					border-radius: 42rpx 42rpx 42rpx 42rpx;
					opacity: 1;
					text-align: center;
					font-size: 32rpx;
					font-weight: bold;
					color: #333333;
			
				}
			}
		}
	}
</style>
